package com.sakura.commonUtil.thread.One;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;

/**
 * Created by apple on 2018/8/9.
 *
 * This annotation is used on classes which define beans. @Configuration is an analog for XML configuration file –
 * it is configuration using Java class. Java class annotated with @Configuration is a configuration by itself and
 * will have methods to instantiate and configure the dependencies.
 *
 * 先放着，有时间弄下限流
 */
@Configuration
public class ExecutorConfig {

    /** 核心线程数 线程池维护线程的最少数量. */
    private int corePoolSize = 40;
    /** 线程池维护线程的最大数量. */
    private int maxPoolSize = 60;
    /** 线程池所使用的缓冲队列. */
    private int queueCapacity = 20;

    /**
     *
     * @description 这里我想用作限流池
     * @author lli
     * @create 2017年8月29日上午10:32:02
     * @version 1.0
     * @return
     */
    @Bean
    public Executor pool() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(corePoolSize);
        executor.setMaxPoolSize(maxPoolSize);
        executor.setQueueCapacity(queueCapacity);
        executor.setThreadNamePrefix("iflytek-pool-");
        executor.initialize();
        return executor;
    }
}
